<%--
  - Author		:	Jaewon Choi
  - Date			:
  - Description	:	
  --%>
<%@ page language="java" %>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/pages/includes/taglibs.jspf" %>
<%@ include file="/WEB-INF/pages/includes/variables.jspf" %>
<%@ include file="/WEB-INF/pages/includes/doctype.jspf" %>
<c:choose>
	<c:when test="${not empty category}">
		<c:set var="fAct" value="수정" />
	</c:when>
	<c:otherwise>
		<c:set var="fAct" value="등록" />
	</c:otherwise>
</c:choose>
<html>
	<head>
<%@ include file="/WEB-INF/pages/includes/metatags.jspf" %>
		<title><fmt:message key="pages.title" /></title>
		<link rel="stylesheet" type="text/css" href="<c:url value="${dirStyles}/common.css" />" />
		<link rel="stylesheet" type="text/css" href="<c:url value="${dirScripts}/jqueryUi/css/ui-lightness/jquery-ui-1.8.21.custom.css" />" />

		<script type="text/javascript" src="<c:url value="${dirScripts}/jquery-1.7.2.min.js" />"></script>
		<script type="text/javascript" src="<c:url value="${dirScripts}/jquery-ui-1.8.21.custom.min.js" />"></script>
		<script type="text/javascript">
			$(function(){
			});
			
			function chkDuplNm(){
				var idx = "0";
				var name = document.frm.name.value;
				if(document.frm.idx){
					idx = document.frm.idx.value;
				}
				
				$.ajax({
					type: "POST",
					url: "<c:url value="/category/chkDupl" />",
					dataType: "json",
					async: false,
					data: {
								"idx" : idx,
								"chkName" : name
							},
					success: function(data){
						if(data.resultCode == "200"){
							chkDuplNmFlag = data.result;
							if(! eval(chkDuplNmFlag)){
								$(document.frm.name).css("background", "#ADC900");
							}else{
								$(document.frm.name).css("background", "#F2685E");
							}
						}else{
							alert(data.errMsg);
						}
					},
					beforeSend: function(){
					},
					error: function(jqXHR, textStatus, errorThrown){
						//alert(jqXHR.responseText); //에러 페이지 내용
						alert("오류가 발생하였습니다.\n관리자에게 문의 바랍니다.");
						throw errorThrown;
					},
					complete: function(){
					}
				 });
				return eval(chkDuplNmFlag);
			}

			function validation(){
				try{
					
					/*
					if((document.frm.customerIdx.value).replace(/\s/g, '') == ""){
						alert("[회원사]은 필수 입력 항목입니다.");
						document.frm.customerIdx.focus();
						return false;
					}
					*/
					
					if((document.frm.name.value).replace(/\s/g, '') == ""){
						alert("[카테고리명]은 필수 입력 항목입니다.");
						document.frm.name.focus();
						return false;
					}					
					
					if(chkDuplNm()){
						alert("[카테고리명]은 중복될 수 없습니다.");
						document.frm.name.focus();
						return false;
					}
					
					if((document.frm.desc1.value).replace(/\s/g, '') == ""){
						alert("[카테고리 설명]은 필수 입력 항목입니다.");
						document.frm.desc1.focus();
						return false;
					}
					
					if((document.frm.desc2.value).replace(/\s/g, '') == ""){
						alert("[매거진 소개]은 필수 입력 항목입니다.");
						document.frm.desc2.focus();
						return false;
					}			
					
					<c:if test="${empty category}">
						if((document.frm.logoFile.value).replace(/\s/g, '') == ""){
							alert("[이용방법 안내]은 필수 입력 항목입니다.");
							document.frm.logoFile.focus();
							return false;
						}
					</c:if>
					
					if((document.frm.iosAppVer.value).replace(/\s/g, '') == ""){
						alert("[iOS 앱버전]은 필수 입력 항목입니다.");
						document.frm.iosAppVer.focus();
						return false;
					}	
					if((document.frm.iosAppLink.value).replace(/\s/g, '') == ""){
						alert("[iOS 앱링크]은 필수 입력 항목입니다.");
						document.frm.iosAppLink.focus();
						return false;
					}	
					if((document.frm.androidAppVer.value).replace(/\s/g, '') == ""){
						alert("[Android  앱버전]은 필수 입력 항목입니다.");
						document.frm.androidAppVer.focus();
						return false;
					}	
					if((document.frm.androidAppLink.value).replace(/\s/g, '') == ""){
						alert("[Android  앱링크]은 필수 입력 항목입니다.");
						document.frm.androidAppLink.focus();
						return false;
					}
					
				}catch(err){
					return false;
				}
				
				return confirm("${fAct} 하시겠습니까?");
			}
		</script>
	</head>
	<body>
		<div class="bodyWrap">
<%@ include file="/WEB-INF/pages/includes/header.jsp" %>
<%@ include file="/WEB-INF/pages/includes/left.jsp" %>
			<div class="contWrap">
				<div class="menuTitle">
					브랜드 >  ${fAct}
				</div>
				<form id="frm" name="frm" method="post" enctype="multipart/form-data" action="<c:url value="/category/submit.do" />" onsubmit="return validation();">
					<input type="hidden" name="maxnum" value="${param.maxnum}" />
					<input type="hidden" name="page" value="${param.page}" />
					<input type="hidden" name="searchName" value="${param.searchName}" />
					<input type="hidden" name="customerIdx" value="${sessionScope.cIdx}" />
					
					
					<table class="frmTbl">
						<colgroup>
							<col width="130px;" />
							<col width="*" />
						</colgroup>
						<tbody>
							<c:if test="${not empty category}">
			 					<tr>
									<th>브랜드 IDX</th>
									<td>
										${category.idx}
										<input type="hidden" name="idx" value="${category.idx}">
									</td>
								</tr>
			 				</c:if>
			 				<!-- 
			 				<tr>
								<th>회원사명*</th>								
								<td><select class="customerIdx" name="customerIdx">
										<option value="" <c:if test="${empty category.customerIdx}"> selected="selected" </c:if>>회원사 선택</option>
									<c:forEach items="${customerList}" var="customer">
										<option value="${customer.idx}" <c:if test="${category.customerIdx eq customer.idx}"> selected="selected" </c:if>>${customer.name}</option>
									</c:forEach>
								</td>
							</tr>
							 -->
							<tr>
								<th>카테고리명*</th>
								<td>
									<input type="text" name="name" style="width: 660px;" maxlength="20" value="<c:out value="${category.name}" />" />
								</td>
							</tr>
							<tr>
								<th>브랜드 설명*</th>
								<td>
									<input type="text" name="desc1" style="width: 660px;" maxlength="1000" value="<c:out value="${category.desc1}" />" />
								</td>
							</tr>							 
							<tr>
								<th>매거진 소개*</th>
								<td>									
									<textarea name="desc2" style="height: 150px; width: 650px;">${category.desc2}</textarea>
								</td>
							</tr>							 
							<tr>
								<th>이용방법 안내*</th>
								<td>
									<input type="file" id="logoFile" name="logoFile" />
									<c:if test="${not empty category.logoUrl}">
										<br /><img src="<c:out value="${category.logoUrl}" />" class="thumbnailImg" />
									</c:if>
								</td>
							</tr>
							<tr>
								<th>iOS 앱버전*</th>
								<td>
									<input type="text" name="iosAppVer" style="width: 160px;" maxlength="1000" value="<c:out value="${category.iosAppVer}" />" />
								</td>
							</tr>
							<tr>
								<th>iOS 앱링크*</th>
								<td>
									<input type="text" name="iosAppLink" style="width: 660px;" maxlength="1000" value="<c:out value="${category.iosAppLink}" />" />
								</td>
							</tr>
							<tr>
								<th>Android 앱버전*</th>
								<td>
									<input type="text" name="androidAppVer" style="width: 160px;" maxlength="1000" value="<c:out value="${category.androidAppVer}" />" />
								</td>
							</tr>
							<tr>
								<th>Android 앱링크*</th>
								<td>
									<input type="text" name="androidAppLink" style="width: 660px;" maxlength="1000" value="<c:out value="${category.androidAppLink}" />" />
								</td>
							</tr>
						</tbody>
					</table>
					<input type="button" class="btn" value="취소" onclick="javascript:document.listFrm.submit();" />
					<input type="submit" class="btn" value="${fAct}" />
					<c:if test="${not empty category}">
						<input type="button" class="btn" value="삭제" onclick="javascript:if(confirm('삭제 하시겠습니까?')){document.removeFrm.submit();}" />
					</c:if>
				</form>
				<form name="listFrm" action="<c:url value="/category/list.do" />" method="post" style="display: none;">
					<input type="hidden" name="maxnum" value="${param.maxnum}" />
					<input type="hidden" name="page" value="${param.page}" />
					<input type="hidden" name="name" value="${param.searchName}" />
				</form>
				
				<form name="removeFrm" action="<c:url value="/category/remove.do" />" method="post" style="display: none;">
					<input type="hidden" name="fAct" value="remove">
					<input type="hidden" name="idx" value="${category.idx}">
					<input type="hidden" name="maxnum" value="${param.maxnum}" />
					<input type="hidden" name="page" value="${param.page}" />
					<input type="hidden" name="searchName" value="${param.searchName}" />
				</form>
			</div>
<%@ include file="/WEB-INF/pages/includes/footer.jsp" %>
		</div>
	</body>
</html> 